package com.kunlun.basedata.option.controller;

import com.kunlun.basedata.option.model.NavigationModel;
import com.kunlun.basedata.option.model.vo.NavigationVo;
import com.kunlun.basedata.option.service.INavigateService;
import com.kunlun.common.utils.ResponseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/navigate")
public class NavigateController {

    private Logger log = LogManager.getLogger();

    @Autowired
    private INavigateService navigateService;

    @RequestMapping(value = "/getAllNavigate", method = RequestMethod.GET)
    public Object getAllNavigate(NavigationVo model) {
        try {
            List<NavigationVo> navigationVos = navigateService.getAllNavigate(model);
            return ResponseUtil.successResponse(navigationVos);
        } catch (Exception e) {
            log.error("NavigateController getAllNavigate Error: ", e);
            return ResponseUtil.failedResponse("获取系统菜单失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/addNavigate", method = RequestMethod.POST)
    public Object addNavigate(String data) {
        try {
            navigateService.addNavigate(data);
            return ResponseUtil.successResponse("success");
        } catch (Exception e) {
            log.error("NavigateController addNavigate Error: ", e);
            return ResponseUtil.failedResponse("新增系统菜单失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/updateNavigate", method = RequestMethod.POST)
    public Object updateNavigate(NavigationModel model) {
        try {
            navigateService.updateNavigate(model);
            return ResponseUtil.successResponse("success");
        } catch (Exception e) {
            log.error("NavigateController updateNavigate Error: ", e);
            return ResponseUtil.failedResponse("编辑系统菜单失败！", e.getMessage());
        }
    }
}
